idtemp=str2double(getenv('SGE_TASK_ID'));

year=all_years(idtemp);

% Probability distribution of Ychosen|X
condprobsmen_temp=load('probs_allyears_data.mat',['condprobsmen' num2str(year) '_140']);
condprobsmen=condprobsmen_temp.(['condprobsmen' num2str(year) '_140']);
PYX_cond=[condprobsmen(:,2:end) condprobsmen(:,1)]; %4x5
%Note: PYX_cond(x,y)=Probability to marry woman y born in any year conditional on being man x born in 1940

% Probability distribution of Xchosen|Y
condprobswomen_temp=load('probs_allyears_data.mat',['condprobswomen' num2str(year+1) '_140']);
condprobswomen=condprobswomen_temp.(['condprobswomen' num2str(year+1) '_140']);
PXY_cond=[condprobswomen(:,2:end) condprobswomen(:,1)];  %4x5
%Note: PXY_cond(y,x)=Probability to marry man x born in any year conditional on being woman y born in 1941

% Probability distribution of X
probsmen_temp=load('probs_allyears_data.mat',['probsmen' num2str(year) '_140']);
PX=probsmen_temp.(['probsmen' num2str(year) '_140']);
%PX(x)=Probability of being man x conditional on being born in 1940

% Probability distribution of Y
probswomen_temp=load('probs_allyears_data.mat',['probswomen' num2str(year+1) '_140']);
PY=probswomen_temp.(['probswomen' num2str(year+1) '_140']);
%PY(y)=Probability of being woman y conditional on being born in 1941




[U_Gumbel, V_Gumbel, Phi_Gumbel, ~,~,~]=param_Gumbel_closedform(PYX_cond, PXY_cond, ntypes_m, ntypes_w);

                                                                                                                 
save(sprintf('%d.mat',year), 'PYX_cond','PXY_cond',...
     'U_Gumbel', 'V_Gumbel','Phi_Gumbel')
                                                                                                                             
